package com.tingyuge.thinking.spring.configuration.bean.definition;

import com.tingyuge.thinking.spring.ioc.overview.domain.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author xiaodao
 * @version 1.0
 * @date 2021/6/15
 */
public class BeanAliasDemo {
    public static void main(String[] args) {
        /*配置 xml 配置文件*/
        //获取 spring 应用上下文
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("META-INF/bean-definitions-context.xml");
        //通过别名 xiaodao-user 获取曾用名 user的bean
        User xiaodaoUser = beanFactory.getBean("xiaodao-user", User.class);
        User user = beanFactory.getBean("user", User.class);
        System.out.println("xiaodao-user 是否与 user bean 相同 "+ xiaodaoUser.equals(user));
    }
}
